package com.tianze.tzkf;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import com.alipay.api.AlipayCallBack;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayResponse;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.ZolozAuthenticationCustomerSmilepayInitializeRequest;
import com.alipay.api.response.ZolozAuthenticationCustomerSmilepayInitializeResponse;

import com.alipay.iot.sdk.APIManager;
import com.alipay.zoloz.smile2pay.service.Zoloz;
import com.google.gson.Gson;
import com.seedien.cardreader.idvender.BaseIDCardLib;
import com.seedien.cardreader.util.IdCardUtil;
import com.tianze.tzkf.base.BaseActivity;
import com.tianze.tzkf.bean.GetSmilePayMsgBean;
import com.tianze.tzkf.bean.LoginClientIdBean;
import com.tianze.tzkf.bean.PayingWithFaceReplyBean;
import com.tianze.tzkf.bean.SmileAuthTokenBean;
import com.tianze.tzkf.bean.Token;
import com.tianze.tzkf.net.RetrofitFactory;
import com.tianze.tzkf.utils.ApkInfoUtil;
import com.tianze.tzkf.utils.ToastUtils;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Zcyang on 2018/12/21.
 */
public class WebSocketActivity extends BaseActivity  {
    @BindView(R.id.textView)
    TextView textView;

    private String address = "wss://online02.tiaze.com:8282";
    private URI uri;
    private static String TAG = WebSocketActivity.class.toString();
  //  private WebSocketClient mWebSocketClient;

    private Zoloz zoloz;
    public static final String KEY_INIT_RESP_NAME = "zim.init.resp";

    // 值为"1000"调用成功
    // 值为"1003"用户选择退出
    // 值为"1004"超时
    // 值为"1005"用户选用其他支付方式
    static final String CODE_SUCCESS = "1000";
    static final String CODE_EXIT = "1003";
    static final String CODE_TIMEOUT = "1004";
    static final String CODE_OTHER_PAY = "1005";

    static final String TXT_EXIT = "已退出刷脸支付";
    static final String TXT_TIMEOUT = "操作超时";
    static final String TXT_OTHER_PAY = "已退出刷脸支付";
    static final String TXT_OTHER = "抱歉未支付成功，请重新支付";

    //刷脸支付相关
    static final String SMILEPAY_CODE_SUCCESS = "10000";
    static final String SMILEPAY_SUBCODE_LIMIT = "ACQ.PRODUCT_AMOUNT_LIMIT_ERROR";
    static final String SMILEPAY_SUBCODE_BALANCE_NOT_ENOUGH = "ACQ.BUYER_BALANCE_NOT_ENOUGH";
    static final String SMILEPAY_SUBCODE_BANKCARD_BALANCE_NOT_ENOUGH = "ACQ.BUYER_BANKCARD_BALANCE_NOT_ENOUGH";

    static final String SMILEPAY_TXT_LIMIT = "刷脸支付超出限额，请选用其他支付方式";
    static final String SMILEPAY_TXT_EBALANCE_NOT_ENOUGH = "账户余额不足，支付失败";
    static final String SMILEPAY_TXT_BANKCARD_BALANCE_NOT_ENOUGH = "账户余额不足，支付失败";
    static final String SMILEPAY_TXT_FAIL = "抱歉未支付成功，请重新支付";
    static final String SMILEPAY_TXT_SUCCESS = "刷脸支付成功";


//    @SuppressLint("HandlerLeak")
//    private Handler mHandler = new Handler() {
//
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            switch (msg.what) {
//                case 1:
//                    LoginClientIdBean loginClientIdBean = (LoginClientIdBean) msg.obj;
//                    int i = 1;
//                    textView.setText("login" + i++ + "");
//                    setDeviceOnLine(loginClientIdBean);
//                    break;
//                case 2:
//                    initSockect();
//                    break;
//                case 3:
//                    GetSmilePayMsgBean getSmilePayMsgBean = (GetSmilePayMsgBean) msg.obj;
//                    int j = 1;
//                    textView.setText("pay" + j++ + "");
//                    startSmilePay(getSmilePayMsgBean);
//
//                    break;
//            }
//        }
//    };
//    private SmileAuthTokenBean.DataBeanX.DataBean data;
//    private Map mockInfo;
//    private String token;

    @Override
    protected void reflshData() {

    }

//    private void startSmilePay(final GetSmilePayMsgBean getSmilePayMsgBean) {
//
//
//        token = readToken().getToken();
//        Map<String, String> request = new HashMap<>();
//        request.put("token", token);
//
//        Observable<SmileAuthTokenBean> smileAuthToken = RetrofitFactory.getInstance(TAG).getSmileAuthToken(request);
//        smileAuthToken.subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<SmileAuthTokenBean>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//
//                    }
//
//                    @Override
//                    public void onNext(SmileAuthTokenBean smileAuthTokenBean) {
//                        if (smileAuthTokenBean.getCode() == 10001) {
//
//                            ToastUtils.showToast(WebSocketActivity.this, "调用刷脸SDK");
//
//                            data = smileAuthTokenBean.getData().getData();
//                            mockInfo = mockInfo();
//                            zoloz.zolozGetMetaInfo(mockInfo, smileToPayResponse -> {
//                                if (smileToPayResponse == null) {
//                                    Log.e(TAG, "response is null");
//                                    promptText(TXT_OTHER);
//                                    return;
//                                }
//                                String code = (String)smileToPayResponse.get("code");
//                                String metaInfo = (String)smileToPayResponse.get("metainfo");
//
//
//                                //获取metainfo成功
//                                if (CODE_SUCCESS.equalsIgnoreCase(code) && metaInfo != null) {
//                                    Log.i(TAG, "metanfo is:" + metaInfo);
//
//                                    //正式接入请上传metaInfo到服务端，不要忘记UrlEncode，使用服务端使用的sdk从服务端访问openapi获取zimId和zimInitClientData；
//                                    AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
//                                            data.getAppId(),
////                                            "2017031806275797",
//                                            data.getRsaPrivateKey(),
////                                                "MIIEowIBAAKCAQEA6AqmRzgltnCQi9nmFP6fHcnQKdbdh2NY03fhTXyXoiWqawFFqpYtnTNJk+1es8h9UhMJ8xNqUdAvNV+fjNSn/C2Iv0TuEVAv/oNfiIev5r4K+KDvT/KqCnv1+lbC4/ILkWEUwalbwSiPcXAHCNI6rsd8LAlodK2MmwzfL+q1R83tqqXV5VMc5QPEHZV09rnBVd26AfcX9mAabwDA0/nBmvhd1dMoVFBvjv8fM7DgQ9RMX4weSC4Sg6u2y9F8+uF8+nu+LxLPXzTyZdmH8ROHreoRnUMxDWZCF0QSbsemhZSCW+cYBcidTehdmfZ4sczIig3iumrW/3DabZWClPVkfwIDAQABAoIBAFZEZ09BC5xJOyQTTZvukd90QUTc0h1cjRCJmCTDtmgdEr+XiHwEO08fWzJ45GV4m0bhNyi8xiFGgdaZB2tHQHDbyOQ7Tzr2kfFQjDrpHzds3g1TX8VcVWVycp+wk+JFAZH6AsqBGVC1sKae3K6l4hVKqtqAYOpH/2dBoNRisSTRMEvFgqyrmiNHIuOCRVQRp6WAEQfkmlJ+QBfRry8VYWE2WSXpLryLmM7UfPTJTDdGugP6yenP1tVB2EBsMo9VvbzkdFtQPucpED0+Kxa4xdkuoY5JmgYGqyj6+7vR7WYAVoBZPxsJrdwmCxJoNrT7czluhIQ7qR373kSV0tsXWmkCgYEA+eBuU6lfV3LCeerhVnbFDChKLvhkHH7pG/HxQV1n90ZHyZpmqwx5rBE3UGuxhukJiwPUmE2NewZKoQ+MnMcygtjoXyXS5bHIJ6ZpgM90yzoWpub+NCiTgh818i/9Ov/iCvlkJJ0jBcSSpiZC6R0IHikAewDF0gS61qFftnzYqBMCgYEA7bpVHMck92sTclPZ4e9EEbMvTUynZRdc6O18hxf1rKHVhyX5zM9dFG6K3A8dpp2+D1fnqr8r5/iuSLj0ZLAfrv1mAqwxx15EOzMdMCweLbTebkkBwEiZibnE1/BkV+rMC5kbnxaPE6fujsvPHoO8JG2fDVDuZVITaGVxAmUFN2UCgYAM6ulJMexX3ProypeznJg7NKoBG54xSu5KH4vVUTrasatsZKsCFLcFii5N3gNjchCoOx52cSvrPDwHb4JZaILX+NaqdI4eib5LLnMt0Yu8Jdid8Dsb/y0BARQM3SY+MpRA9PuUWPtChRL/u+KhonqU9JGtyjBv1wbBqb4E9RdOOQKBgQCNOKffFJ5tLHq86/r/MLfrG9r5vJOkhiB3br0PM7iJ+Qlz46dld7n/rTtoRsKCfCqvyrSgxjg68Yv3P4hPWCE6PuYeqFRZ7zHxSQgJ2euDk3KfaVdU9sve+TBqZy/02lKkgSvbcfdE4fnhckl0AyX9LfHSY0V7gypsVfawSXqz0QKBgGsv8cR2cpqReCHQbRygbGRWsVNWl4hlznVMoDzSPb3SFD02iMheYf4hWBjuvy5+jLjWumlWr+LvfQoRJfhkAbfIrlq9o8oIxT4ehk/XQ4RPZ7j2xAqtVcR/f4Dax4tdHEMGB2rjWwPPpaoEfU1PVyW9TaHoD/5rhCt6y/UEuJdC\n",
//                                            "json",
//                                            "utf-8",
//                                            null,
//                                            "RSA2");
//
////                                    ZolozAuthenticationCustomerSmilepayInitializeRequest
//                                    ZolozAuthenticationCustomerSmilepayInitializeRequest request1
//                                            = new ZolozAuthenticationCustomerSmilepayInitializeRequest();
//
//                                    // zolozGetMetaInfo接口返回的metainfo对象中加入业务参数
//                                    JSONObject zimmetainfo = JSON.parseObject(metaInfo);
//                                    JSONObject merchantInfo = zimmetainfo.getJSONObject("merchantInfo");
//                                    merchantInfo.put("pay_amount", getSmilePayMsgBean.getMsg().getPay_amount());//可选，支付币种订单金额,值为double类型
//                                    merchantInfo.put("pay_currency", "CNY");//可选，支付币种，目前仅支持 人民币：CNY
//
//                                    JSONObject extInfo = new JSONObject();
//
//                                    /* start: 如果是姓名＋身份证号方式的刷脸支付，请加入以下代码 */
//                                    extInfo.put("certNo", card_Id); //必填，当前被认证用户的身份证号
//                                    extInfo.put("certName", card_Name);//必填，当前被认证用户的姓名（保持和身份证一致）
//                                    extInfo.put("certType", "IDCARD"); //必填，写为IDCARD，表明身份证
//                                    extInfo.put("bizType", "8"); //必填，固定写为8，表明基于姓名和身份证号的刷脸支付场景
//                                    /* end: -------------------------------------------- */
//
//
//                                    String app_auth_token = smileAuthTokenBean.getData().getData().getApp_auth_token();
//                                    JSONObject biz = new JSONObject();
////                                    zimmetainfo.put("extInfo", extInfo);
////                                    biz.put("zimmetainfo", metaInfo);
////                                    zimmetainfo.put("extInfo", extInfo);
////                                    request1.setBizContent(biz.toJSONString());
//                                    request1.putOtherTextParam("app_auth_token", app_auth_token);
//                                    //如果有身份证信息就传extinfo
//                                    if (!card_Id .equals("") && !card_Name.equals("")) {
//                                        zimmetainfo.put("extInfo", extInfo);
//                                    }
//                                    request1.setBizContent(zimmetainfo.toJSONString());
//
//                                   /* request1.setBizContent("{" +
//                                            "    \"app_id\":\"2088031379002395\"" +
//                                            "  }");*/
//
//
//                                    //起一个异步线程发起网络请求
//                                    alipayClient.execute(request1,
//                                            new AlipayCallBack() {
//                                                @Override
//                                                public AlipayResponse onResponse(AlipayResponse response) {
//                                                    if (response != null && SMILEPAY_CODE_SUCCESS.equals(response.getCode())) {
//                                                        try {
//                                                            ZolozAuthenticationCustomerSmilepayInitializeResponse zolozResponse
//                                                                    = (ZolozAuthenticationCustomerSmilepayInitializeResponse)response;
//
//                                                            String result = zolozResponse.getResult();
//                                                            JSONObject resultJson = JSON.parseObject(result);
//                                                            String zimId = resultJson.getString("zimId");
//                                                            String zimInitClientData = resultJson.getString("zimInitClientData");
//                                                            //人脸调用
//                                                            smile(zimId, zimInitClientData,getSmilePayMsgBean);
//                                                        } catch (Exception e) {
//                                                            promptText(TXT_OTHER);
//                                                        }
//                                                    } else {
//                                                        promptText(TXT_OTHER);
//                                                        Log.e(TAG, "SMILEPAY_CODE_SUCCESS :" + SMILEPAY_CODE_SUCCESS);
//                                                        Log.e(TAG, "Code :" + response.getCode());
//                                                    }
//                                                    return null;
//                                                }
//                                            });
//                                } else {
//                                    promptText(TXT_OTHER);
//
//                                }
//                            });
//                        }
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//
//                    }
//
//                    @Override
//                    public void onComplete() {
//
//                    }
//                });
//
//
//    }


//    /**
//     * 发起刷脸支付请求.
//     * @param zimId 刷脸付token，从服务端获取，不要mock传入
//     * @param protocal 刷脸付协议，从服务端获取，不要mock传入
//     * @param getSmilePayMsgBean
//     */
//    private void smile(String zimId, String protocal, GetSmilePayMsgBean getSmilePayMsgBean) {
//        Map params = new HashMap();
//        params.put(KEY_INIT_RESP_NAME, protocal);
//
//        zoloz.zolozVerify(zimId, params, smileToPayResponse -> {
//            if (smileToPayResponse == null) {
//                promptText(TXT_OTHER);
//                return;
//            }
//            ToastUtils.showToast(this,smileToPayResponse.toString());
//
//            String code = (String)smileToPayResponse.get("code");
//            String fToken = (String)smileToPayResponse.get("ftoken");
//            String subCode = (String)smileToPayResponse.get("subCode");
//            String msg = (String)smileToPayResponse.get("msg");
//            Log.d(TAG, "get_ftoken is:" + fToken);
//
//
//            //刷脸成功
//            if (CODE_SUCCESS.equalsIgnoreCase(code) && fToken != null) {
//                //promptText("刷脸成功，返回ftoken为:" + fToken);
//                //这里在Main线程，网络等耗时请求请放在异步线程中
//                //后续这里可以发起支付请求
//                //https://docs.open.alipay.com/api_1/alipay.trade.pay
//                //需要修改两个参数
//                //scene固定为security_code
//                //auth_code为这里获取到的fToken值
//                //支付一分钱，支付需要在服务端发起，这里只是模拟
//                Log.e(TAG, "set_ftoken is:" + fToken);
//                smilePay(getSmilePayMsgBean,fToken, token);
//
//            } else if (CODE_EXIT.equalsIgnoreCase(code)) {
//                promptText(TXT_EXIT);
//            } else if (CODE_TIMEOUT.equalsIgnoreCase(code)) {
//                promptText(TXT_TIMEOUT);
//            } else if (CODE_OTHER_PAY.equalsIgnoreCase(code)) {
//                promptText(TXT_OTHER_PAY);
//            } else {
//                String txt = TXT_OTHER;
//                if (!TextUtils.isEmpty(subCode)) {
//                    txt = txt + "(" + subCode + ")";
//                }
//                promptText(txt);
//            }
//        });
//    }
//
//    private void smilePay(GetSmilePayMsgBean getSmilePayMsgBean, String ftoken, String token) {
//
//        Map<String, String> request = new HashMap<>();
//        String amount = getSmilePayMsgBean.getMsg().getPay_amount();
//
//        request.put("token",token);
//        request.put("ftoken",ftoken);
//        request.put("type",ftoken);
//
//        String terminal_id = getSerialNumber();
//        if (terminal_id != null && !terminal_id.equals("")) {
//            request.put("terminal_id",getSerialNumber());
//        } else {
//            terminal_id = ApkInfoUtil.getANDROID_ID(this);
//            request.put("terminal_id",terminal_id);
//        }
//
//        request.put("port","pos");
//        request.put("payways","alipay");
//        request.put("amount", amount);
//        request.put("remark","备注");
//
//        Log.e(TAG, "set_ftoken is:" + ftoken);
//
//        Observable<PayingWithFaceReplyBean> smilePay = RetrofitFactory.getInstance(TAG).smilePay(request);
//
//        smilePay.subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<PayingWithFaceReplyBean>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//                        Log.e("刷脸收款失败onSubscribe",">>>>>>");
//                    }
//
//                    @Override
//                    public void onNext(PayingWithFaceReplyBean payingWithFaceReplyBean) {
//                        if (payingWithFaceReplyBean == null) {
//                            ToastUtils.showToast(WebSocketActivity.this,"payingWithFaceReply: " + payingWithFaceReplyBean);
//                            Log.e("刷脸收款失败1",payingWithFaceReplyBean+">>>>>>");
//
//                            return;
//                        }
//                        if (payingWithFaceReplyBean.getCode().equals("10001")) {
//                            String content = "刷脸收款成功  ¥" + amount + " " + getCurrentTime();
//                            Log.e("刷脸收款成功",payingWithFaceReplyBean.getMsg()+">>>>>>");
//
//                            /*model.startGt(ISharedPreference.getInstance(getApplication()).getCid(), "天择可付推送提醒", content, () -> {
//                                BaiduSpeechClient.getInstance().speak("收款" + amount + "元");
//                            });*/
////                            showPrintDialog(payingWithFaceReplyBean);
////                            print(payingWithFaceReplyBean);
//                            ToastUtils.showToast(WebSocketActivity.this, "支付状态：" + payingWithFaceReplyBean.getMsg());
//                        } else {
//                            Log.e("刷脸收款失败",payingWithFaceReplyBean.getMsg()+">>>>");
//                            ToastUtils.showToast(WebSocketActivity.this, payingWithFaceReplyBean.getMsg());
//                        }
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        Log.e("刷脸收款失败onError",">>>>>>");
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        Log.e("刷脸收款失败onComplete",">>>>>>");
//                    }
//                });
//
//
//    }
//
//
//    /**
//     * mock数据，真实商户请填写真实信息.
//     */
//    private Map mockInfo() {
//        Map merchantInfo = new HashMap();
//        //以下信息请根据真实情况填写
//        //商户 Pid
//        merchantInfo.put("merchantId", data.getMerchantId());
////        merchantInfo.put("merchantId", "2088031379002395");
//        //ISV PID
//        merchantInfo.put("partnerId", data.getPartnerId());
////        merchantInfo.put("partnerId", "2088421609886161");
//        //添加刷脸付功能的appid
//        merchantInfo.put("appId", data.getAppId());
////        merchantInfo.put("appId", "2017031806275797");
//        //机具编号，便于关联商家管理的机具
//        String serialNumber = getSerialNumber();
//        if (serialNumber != null && !serialNumber.equals("")) {
//            merchantInfo.put("deviceNum", getSerialNumber());
//        } else {
//            serialNumber = ApkInfoUtil.getANDROID_ID(this);
//            merchantInfo.put("deviceNum", serialNumber);
//        }
//        //商户的门店编号
//        merchantInfo.put("storeCode", data.getStoreCode());
//        //支付宝门店编号
//        merchantInfo.put("alipayStoreCode", data.getBrandCode());
//
//        return merchantInfo;
//    }
//
//    /**
//     * 发起刷脸支付请求.
//     * @param txt toast文案
//     */
//    void promptText(final String txt) {
//        runOnUiThread(() -> Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_LONG).show());
//    }


    private void setDeviceOnLine(LoginClientIdBean loginClientIdBean) {

        Map<String, String> request = new HashMap<>();
        request.put("type", loginClientIdBean.getType());
        request.put("login_type", "2");
        request.put("client_id", loginClientIdBean.getClient_id());
      //  request.put("user_phone", getSerialNumber());

        String serialNumber = getSerialNumber();
        if (serialNumber != null && !serialNumber.equals("")) {
            request.put("user_phone", serialNumber);
            Log.e("getSerialNumber", ">>" + serialNumber);
        } else {
            serialNumber = ApkInfoUtil.getANDROID_ID(this);
            Log.e("getANDROID_ID", ">>" + serialNumber);
            request.put("user_phone", serialNumber);
        }

        Observable<Token> setDeviceOnLine = RetrofitFactory.getInstance(TAG).setDeviceOnLine(request);
        setDeviceOnLine.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Token>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Token token) {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }


    @Override
    protected void initData() {
      //  zoloz = Zoloz.getInstance(getApplicationContext());
    }

    @Override
    protected void initTitle() {
        initSockect();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_web_socket;
    }

    @Override
    protected void isNetConnect(boolean isNetChanges) {

    }

//    public void initSockect() {
//        try {
//            uri = new URI(address);
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        }
//        if (null == mWebSocketClient) {
//            mWebSocketClient = new WebSocketClient(uri) {
//                @Override
//                public void onOpen(ServerHandshake serverHandshake) {
//                    Log.i(TAG, "onOpen: ");
//                }
//
//                @Override
//                public void onMessage(String s) {
//                    Log.i(TAG, "onMessage: " + s);
//
//                    Gson gson = new Gson();
//                    LoginClientIdBean loginClientIdBean = gson.fromJson(s, LoginClientIdBean.class);
//                    if (TextUtils.equals("login", loginClientIdBean.getType())) {
//                        Message msg = Message.obtain();
//                        msg.obj = loginClientIdBean;
//                        msg.what = 1;
//                        mHandler.sendMessage(msg);
//                        //                        mHandler.sendMessageDelayed(msg,3000);
//                        return;
//                    }
//                    GetSmilePayMsgBean getSmilePayMsgBean = gson.fromJson(s, GetSmilePayMsgBean.class);
//                    if (TextUtils.equals("smile", getSmilePayMsgBean.getMsg().getType())) {
//                        Message msg = Message.obtain();
//                        msg.obj = getSmilePayMsgBean;
//                        msg.what = 3;
//                        mHandler.sendMessage(msg);
//                        return;
//                    }
//
//                }
//
//                @Override
//                public void onClose(int i, String s, boolean b) {
//                    Log.i(TAG, "onClose: ");
//                    Message msg = Message.obtain();
//                    msg.what = 2;
//                    mHandler.sendMessageDelayed(msg, 3000);
//                }
//
//                @Override
//                public void onError(Exception e) {
//                    Log.i(TAG, "onError: ");
//
//                    Message msg = Message.obtain();
//                    msg.what = 2;
//                    mHandler.sendMessageDelayed(msg, 3000);
//                }
//
//            };
//            mWebSocketClient.connect();
//        }
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
      //  IdCardUtil.getInstance().unregist();
    }

//    //通过反射获取ro.serialno
//    public static String getSerialNumber() {
//
//        String serial = null;
//
//        try {
//
//            Class<?> c = Class.forName("android.os.SystemProperties");
//
//            Method get = c.getMethod("get", String.class);
//
//            serial = (String) get.invoke(c, "ro.serialno");
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//
//        }
//
//        return serial;
//
//    }

//    //读卡器回调接口
//    String card_Name = ""; // 身份证名称
//    String card_Id = ""; // 身份证卡号
//
//    @Override
//    public void sendCardInfo(com.seedien.cardreader.instance.CardInfo cardInfo) {
//        if (cardInfo != null){
//            if (cardInfo.getName() != null && !cardInfo.getName().equals("")){
//                card_Name = cardInfo.getName();
//            }
//
//            if (cardInfo.getId() != null && !cardInfo.getId().equals("")){
//                card_Id = cardInfo.getId();
//            }
//        }
//    }








}
